// pages/list/review.js
const db=wx.cloud.database()
const submit_db=db.collection('submit')
import Toast from '@vant/weapp/toast/toast';
Page({
  review(){
    wx.navigateTo({
      url: '../list/index',
    })
  },
  /**
   * 页面的初始数据
   */
  data: {
    t:[],
    t2:[],
    t3:[],
    QR:[],
    Q1:'',
    Q2:'',
    Q3:'',
    Q4:'',
    Q5:'',
    Q6:'',
    Q7:'',
    Q8:'',
    Q9:'',
    Q10:'',

  },
  infomation(){
    wx.navigateTo({
      url: '../wenjuan/info',
    })
  },
  shujv(){
    for (let i = 1; i < this.data.QR.length+1; i++){
     this.data.t.push(i)
     this.setData({
       t:this.data.t
     })
    }
  },
  part2(){
    for (let i = 1; i < this.data.part2.length+1; i++){
     this.data.t2.push(i)
     this.setData({
       p:this.data.t2
     })
    }
  },
  part3(){
    for (let i = 1; i < this.data.part3.length+1; i++){
     this.data.t3.push(i)
     this.setData({
       p2:this.data.t3
     })
    }
  },
  dj(e){
    var i = e.currentTarget.id
    wx.navigateTo({
      url: '../part2/multiple?id='+i,
    })
  },
  dj2(e){
    var i = e.currentTarget.id
    wx.navigateTo({
      url: '../part2/danxuan?id='+i,
    })
    console.log(i)
  },
  dj3(e){
    var i = e.currentTarget.id
    wx.navigateTo({
      url: '../part2/tiankong?id='+i,
    })
    console.log(i)
  },
  submit(){
    submit_db.add({
      data: {
      version:this.data.bb,
      danxuan:this.data.QR,
      multiple:this.data.part2,
      tiankong:this.data.part3
      //  sex:this.data.info[0],
      //  age:this.data.info[1],
      //  job:this.data.info[2],
      //  vaccine:this.data.info[3],
      //  address:this.data.info[4],
      //  Q1:this.data.QR[0]['select'],
      //  Q2:this.data.QR[1]['select'],
      //  Q3:this.data.QR[2]['select'],
      //  Q4:this.data.QR[3]['select'],
      //  Q5:this.data.QR[4]['select'],
      //  Q6:this.data.QR[5]['select'],
      //  Q7:this.data.QR[6]['select'],
      //  Q8:this.data.QR[7]['select'],
      //  Q9:this.data.QR[8]['select'],
      //  Q10:this.data.QR[9]['select'],
      },
      success: res=>{
        const toast = Toast.loading({
          duration: 0, // 持续展示 toast
          forbidClick: true,
          message: '提交成功!',
          selector: '#custom-selector',
        });
        let second = 2;
        const timer = setInterval(() => {
          second--;
          if (second) {
            toast.setData({
              message: ` ${second} 秒后返回`,
            });
          } else {
            clearInterval(timer);
            Toast.clear();
            wx.redirectTo({
              url: '../wenjuan/index',
            })
          }
        }, 1000);
        wx.removeStorageSync('bb')
        wx.removeStorageSync('regular')
        wx.removeStorageSync('multiple')
        wx.removeStorageSync('tk')
      },
      fail: err => {
        wx.hideLoading()
        wx.showToast({
          icon: 'none',
          title: '网络不给力....'
        })
      }
    })
    
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var getpart2=wx.getStorageSync('multiple')
    this.setData({
      part2:getpart2
    })
    this.part2()
    var getpart3=wx.getStorageSync('tk')
    this.setData({
      part3:getpart3
    })
    this.part3()
    var getQR=wx.getStorageSync('regular')
    this.setData({
      QR:getQR
    })
    this.shujv()
    var getbb=wx.getStorageSync('bb')
    this.setData({
      bb:getbb
    })

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})